tohex.bat - batch file to print a number as hex

Maurits

Hold ∞ in the palm of your hand [B̲̅l̲̅a̲̅k̲̅e̲̅]
Inspired by Matthew Chaboud's comment in Raymond Chen's blog post, <a href="http://blogs.msdn.com/oldnewthing/archive/2006/05/04/589884.aspx">Doing quick arithmetic from the command prompt</a><br><br><br><br><br>
<div style="font-family: monospace;">C:\&gt;tohex -999<br>-0x3E7<br></div>
Posted by Maurits // Thu, May 4, 2006 8:07 PM

Inspired by Matthew Chaboud's comment in Raymond Chen's blog post, Doing quick arithmetic from the command prompt




C:\>tohex -999
-0x3E7
[Save]
  DoomBringer
  Doom!
 
  Thu, May 4 2006 8:00 PM
what, no two's complement?

  Maurits
  Hold ∞ in the palm of your hand [B̲̅l̲̅a̲̅k̲̅e̲̅]
 
  Thu, May 4 2006 8:22 PM
... good catch   Added hack to handle two's complement

EDIT:

Before:
C:\>tohex -2147483648
-0x-80000000

After:
C:\>tohex -2147483648
-0x80000000


  Sven Groot
 
 
  Fri, May 5 2006 10:41 AM
Of course the big question is, how is this easier than firing up calc.exe (especially since there's a button on my keyboard that fires up calc.exe)?

  Maurits
  Hold ∞ in the palm of your hand [B̲̅l̲̅a̲̅k̲̅e̲̅]
 
  Fri, May 5 2006 12:28 PM
It's not easy to use calc.exe if you're a service


  Sven Groot
 
 
  Fri, May 5 2006 2:30 PM
True, that.

  staceyw
  Bouncin'
 
  Tue, May 9 2006 12:22 AM
-999 in hex is FFFFFC19 - no? 

Here is how you might do the same using PowerShell:

PS C:\> (-999).ToString("x")
fffffc19


  Maurits
  Hold ∞ in the palm of your hand [B̲̅l̲̅a̲̅k̲̅e̲̅]
 
  Tue, May 9 2006 11:17 AM

staceyw wrote:
-999 in hex is FFFFFC19 - no?


Sure, on a 32-bit machine.